﻿using System.Collections.Generic;
using System.Data.Common;
using Jayden.Dll.Core;
using Jayden.Dll.Core.Persistence;
using Jayden.Dll.Core.Persistence.Data;
using Jayden.Dll.Core.Persistence.Data.SQLite;
using Jayden.Dll.Core.Persistence.Models;

namespace Jayden.Dll.Series.Providers
{
	public class SQLiteShowInfoDataAccess : SQLiteDataAccess<ShowInfo>
	{
		public SQLiteShowInfoDataAccess(Configuration config, UnitOfWork uow, Entity entity) : base(config, uow, entity) { }

		public IEnumerable<ShowInfo> FindByTitleLike(string titleLike, int? limit = null, int? offset = null)
		{
			string commandText = Helper.GenerateSelect(null, Entity.Table.TableName, "Title LIKE @Title", null, new string[] { "StartDate DESC", "Title" }, limit, offset);
			using (DbCommandProxy command = CreateCommand(commandText))
			{
				CreateParameter(command, "Title", titleLike);
				DbDataReader reader = command.Command.ExecuteReader();
				return EnumerateFromReader(reader);
			}
		}

		public ShowInfo FindById(string id)
		{
			string commandText = Helper.GenerateSelect(Entity, Entity["Id"]);
			using (DbCommandProxy command = CreateCommand(commandText))
			{
				CreateParameter(command, "Id", id);
				DbDataReader reader = command.Command.ExecuteReader();
				return CreateFromReader(reader);
			}
			return null;
		}
	}
}
